feat(desktop): auto-stop server egress when host publish drops#23
Merged
Conversation
When the host's WebRTC publish drops (flaky network / dead secondary NIC), the room-composite egress was left orphaned: LiveKit keeps compositing the now-empty room, burning SFU CPU and pushing dead/frozen frames to every platform until the dead publisher finally times out server-side minutes later (which also re-thrashed the 4-vCPU box and broke subsequent streams). New useAutoStopServerStream hook stops the tracked egress on the hosting true->false transition. A user-initiated stop clears the egress first (isServerStreaming -> false), so it never double-stops, and it never fires before hosting has started. Paired with the start route already stopping pre-existing egress (#22), a crashed host is also cleaned up on next Go Live. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the host's WebRTC publish drops (flaky network / dead secondary NIC — the recurring
dtls timeout~20–90s into a stream), the room-composite egress was left orphaned: LiveKit keeps compositing the now-empty room, burning SFU CPU and pushing dead/frozen frames to every platform ("YouTube isn't getting any data") until the dead publisher finally times out server-side minutes later. On the 4-vCPU box that orphan also re-thrashed CPU and broke subsequent Go Lives.Fix
New
useAutoStopServerStream(isHosting, isServerStreaming, stopServerStream)hook stops the tracked egress on the hostingtrue -> falsetransition. The renderer stays alive during a media drop, so it can issue the stop promptly — well before the server-side participant timeout.isServerStreaming -> false), so it never double-stops.Test
Extracted the logic into a unit-testable hook (
CapturePreviewis too heavy to render in tests). 4 cases: stops on host-drop while streaming; no-op when not streaming; no fire on mount; no fire while hosting stays up. 4/4 pass; full monorepo lint passes.🤖 Generated with Claude Code